package com.example.node.factory;

import com.example.node.Node;
import com.example.node.NodeImpl;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/*
 * @className: NodeFactory
 * @author: chentao
 * @date: 2025/10/25 下午5:49
 * @Version: 1.0
 * @description:
 */
@Service
public class NodeFactory implements InitializingBean, DisposableBean {

    @Value("${ws.serverPort}")
    private Long serverPort;

    private Node node;

    @Override
    public void afterPropertiesSet() throws Exception {
        this.node = new NodeImpl(serverPort);
        this.node.start();
    }

    @Override
    public void destroy() throws Exception {
        this.node.stop();
    }

    public Node getNode() {
        return node;
    }
}
